//
//  SceneryPriceParse.m
//  LocalTravel
//
//  Created by zheng ji on 14-3-20.
//  Copyright (c) 2014年 jxw. All rights reserved.
//

#import "SceneryPriceParse.h"
@interface SceneryPriceParse ()
{
    NSMutableArray* _sceneryPriceArray;
    NSMutableDictionary* _priceDict;
    NSMutableDictionary* _otherParamDict;
    //NSMutableString* _itemValue;
    NSString* _currentElementName;
}
@end

@implementation SceneryPriceParse
-(SceneryPriceParse*)initWithXmlData:(NSString*)xmlData{
    //xmlData=@"<response><body><sceneryList><scenery><ahead><day>3</day><time>08:30</time></ahead></scenery></sceneryList></body></response>";
    NSXMLParser* parser=[[NSXMLParser alloc] initWithData:[xmlData dataUsingEncoding:NSUTF8StringEncoding]];
    parser.delegate=self;
    parser.shouldProcessNamespaces=NO;
    [parser parse];
    
    return  self;
}
-(void)parserDidStartDocument:(NSXMLParser *)parser{
    _sceneryPriceArray=[[NSMutableArray alloc]init];
    _otherParamDict=[[NSMutableDictionary alloc]init];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    _currentElementName=elementName;
    
    if([_currentElementName isEqualToString:@"p"]){
        _priceDict=[[NSMutableDictionary alloc]init];
    }
    //_itemValue=[[NSMutableString alloc]init];
    
    
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    
    if([elementName isEqualToString:@"p"]){
        
        [_sceneryPriceArray addObject:_priceDict];
        _priceDict=nil;
    }
    
    // _itemValue=nil;
    
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)value{
    [_priceDict setObject:value forKey:_currentElementName];
    
    if([_currentElementName isEqualToString:@"day"]){
        [_otherParamDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"time"]){
        [_otherParamDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"useCard"]){
        [_otherParamDict setObject:value forKey:_currentElementName];
    }
    
    /*
    if([_currentElementName isEqualToString:@"policyId"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"policyName"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"remark"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"price"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    
    if([_currentElementName isEqualToString:@"tcPrice"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    
    if([_currentElementName isEqualToString:@"pMode"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"gMode"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    
    if([_currentElementName isEqualToString:@"ticketName"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"day"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"time"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"useCard"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"maxT"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    if([_currentElementName isEqualToString:@"minT"]){
        [_priceDict setObject:value forKey:_currentElementName];
    }
    */
    
}
-(void)parserDidEndDocument:(NSXMLParser *)parser{
    
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
    
}
-(NSMutableDictionary*) getScenaryPriceList{
    [_otherParamDict setObject:_sceneryPriceArray forKey:@"policy"];
    return _otherParamDict;
}
@end
